-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
410 enforce a html formatter and linter #411
Conversation
…jango HTML linting and formatting
@mbarton What are your thoughts on adding linting/formatting to pre-commits or PR checks? By default, djlint does not return a non-zero exit code for lint issues. If you want to fail the pipeline on linting errors, we'd have to run djlint without the --reformat flag and handle warnings as errors?... With this in the pipeline, templates with broken HTML would be prevented from being pushed to live. Thinking wider than template .html files, there's MegaLinter that has black and djlint capabilities... |
Seen on STAGING (created by @reecehill and merged by @eatyourpeas 9 minutes and 44 seconds ago) Please check your changes! |
This pull request includes updates to configuration files, documentation, and HTML templates to enhance code formatting, linting, and developer experience. The most important changes include the addition of a new configuration file for DJLint, updates to VSCode settings and recommendations, and improvements to HTML templates for better readability and consistency.
Configuration Updates:
.djlintrc
configuration file to enforce specific formatting and linting rules for Django templates..vscode/settings.json
to include settings for Python language server, file associations, editor configurations, and DJLint integration..vscode/extensions.json
to recommend extensions for spell checking, Python formatting, Django support, and linting.Documentation Improvements:
code-style.md
with detailed instructions for linting and formatting Python files and Django templates, including usage of DJLint. [1] [2] [3]HTML Template Enhancements:
Developer experience
As per documentation, developers are to continue to using VSCode. No change there.
However, .vscode/extensions.json will advise devs which extensions to have installed (optional). The biggest recommendation added in this PR is the use of "djlint" for linting and formatting Django template files.
To run djlint:
djlint ./project/npda/templates/* --configuration .djlintrc --reformat
djlint ./project/npda/templates/* --configuration .djlintrc --lint
Other linters
I had considered other methods of linting template files with django tags ({{ }}). Including "Django Template Support" and Prettier. The first does a great job, but offers no CLI utility (thinking CI/CD), and Prettier - whilst ideal for tailwindcss management - cannot handle Django tags.